<?php
	/**
	 * The abstract BuildVersionGen class defined here is
	 * code-generated and contains all the basic CRUD-type functionality as well as
	 * basic methods to handle relationships and index-based loading.
	 *
	 * To use, you should use the BuildVersion subclass which
	 * extends this BuildVersionGen class.
	 *
	 * Because subsequent re-code generations will overwrite any changes to this
	 * file, you should leave this file unaltered to prevent yourself from losing
	 * any information or code changes.  All customizations should be done by
	 * overriding existing or implementing new methods, properties and variables
	 * in the BuildVersion class.
	 *
	 * @package My QCubed Application
	 * @subpackage GeneratedDataObjects
	 * @property-read integer $Id the value for intId (Read-Only PK)
	 * @property integer $ProjectId the value for intProjectId 
	 * @property integer $MajorVersion the value for intMajorVersion 
	 * @property integer $MinorVersion the value for intMinorVersion 
	 * @property integer $HotPatch the value for intHotPatch 
	 * @property integer $ReleaseCandidate the value for intReleaseCandidate 
	 * @property QDateTime $DateCreated the value for dttDateCreated 
	 * @property QDateTime $DateModified the value for dttDateModified 
	 * @property integer $CreateUserId the value for intCreateUserId 
	 * @property integer $Status the value for intStatus (Not Null)
	 * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
	 */
	class BuildVersionGen extends QBaseClass implements IteratorAggregate {

		///////////////////////////////////////////////////////////////////////
		// PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
		///////////////////////////////////////////////////////////////////////

		/**
		 * Protected member variable that maps to the database PK Identity column build_version.id
		 * @var integer intId
		 */
		protected $intId;
		const IdDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.project_id
		 * @var integer intProjectId
		 */
		protected $intProjectId;
		const ProjectIdDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.major_version
		 * @var integer intMajorVersion
		 */
		protected $intMajorVersion;
		const MajorVersionDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.minor_version
		 * @var integer intMinorVersion
		 */
		protected $intMinorVersion;
		const MinorVersionDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.hot_patch
		 * @var integer intHotPatch
		 */
		protected $intHotPatch;
		const HotPatchDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.release_candidate
		 * @var integer intReleaseCandidate
		 */
		protected $intReleaseCandidate;
		const ReleaseCandidateDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.date_created
		 * @var QDateTime dttDateCreated
		 */
		protected $dttDateCreated;
		const DateCreatedDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.date_modified
		 * @var QDateTime dttDateModified
		 */
		protected $dttDateModified;
		const DateModifiedDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.create_user_id
		 * @var integer intCreateUserId
		 */
		protected $intCreateUserId;
		const CreateUserIdDefault = null;


		/**
		 * Protected member variable that maps to the database column build_version.status
		 * @var integer intStatus
		 */
		protected $intStatus;
		const StatusDefault = null;


		/**
		 * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
		 * columns from the run-time database query result for this object).  Used by InstantiateDbRow and
		 * GetVirtualAttribute.
		 * @var string[] $__strVirtualAttributeArray
		 */
		protected $__strVirtualAttributeArray = array();

		/**
		 * Protected internal member variable that specifies whether or not this object is Restored from the database.
		 * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
		 * @var bool __blnRestored;
		 */
		protected $__blnRestored;




		///////////////////////////////
		// PROTECTED MEMBER OBJECTS
		///////////////////////////////



		/**
		 * Initialize each property with default values from database definition
		 */
		public function Initialize()
		{
			$this->intId = BuildVersion::IdDefault;
			$this->intProjectId = BuildVersion::ProjectIdDefault;
			$this->intMajorVersion = BuildVersion::MajorVersionDefault;
			$this->intMinorVersion = BuildVersion::MinorVersionDefault;
			$this->intHotPatch = BuildVersion::HotPatchDefault;
			$this->intReleaseCandidate = BuildVersion::ReleaseCandidateDefault;
			$this->dttDateCreated = (BuildVersion::DateCreatedDefault === null)?null:new QDateTime(BuildVersion::DateCreatedDefault);
			$this->dttDateModified = (BuildVersion::DateModifiedDefault === null)?null:new QDateTime(BuildVersion::DateModifiedDefault);
			$this->intCreateUserId = BuildVersion::CreateUserIdDefault;
			$this->intStatus = BuildVersion::StatusDefault;
		}


		///////////////////////////////
		// CLASS-WIDE LOAD AND COUNT METHODS
		///////////////////////////////

		/**
		 * Static method to retrieve the Database object that owns this class.
		 * @return QDatabaseBase reference to the Database object that can query this class
		 */
		public static function GetDatabase() {
			return QApplication::$Database[1];
		}

		/**
		 * Load a BuildVersion from PK Info
		 * @param integer $intId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion
		 */
		public static function Load($intId, $objOptionalClauses = null) {
			// Use QuerySingle to Perform the Query
			return BuildVersion::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::BuildVersion()->Id, $intId)
				),
				$objOptionalClauses
			);
		}

		/**
		 * Load all BuildVersions
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion[]
		 */
		public static function LoadAll($objOptionalClauses = null) {
			if (func_num_args() > 1) {
				throw new QCallerException("LoadAll must be called with an array of optional clauses as a single argument");
			}
			// Call BuildVersion::QueryArray to perform the LoadAll query
			try {
				return BuildVersion::QueryArray(QQ::All(), $objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count all BuildVersions
		 * @return int
		 */
		public static function CountAll() {
			// Call BuildVersion::QueryCount to perform the CountAll query
			return BuildVersion::QueryCount(QQ::All());
		}




		///////////////////////////////
		// QCUBED QUERY-RELATED METHODS
		///////////////////////////////

		/**
		 * Internally called method to assist with calling Qcubed Query for this class
		 * on load methods.
		 * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
		 * @param boolean $blnCountOnly only select a rowcount
		 * @return string the query statement
		 */
		protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();

			// Create/Build out the QueryBuilder object with BuildVersion-specific SELET and FROM fields
			$objQueryBuilder = new QQueryBuilder($objDatabase, 'build_version');
			BuildVersion::GetSelectFields($objQueryBuilder);
			$objQueryBuilder->AddFromItem('build_version');

			// Set "CountOnly" option (if applicable)
			if ($blnCountOnly)
				$objQueryBuilder->SetCountOnlyFlag();

			// Apply Any Conditions
			if ($objConditions)
				try {
					$objConditions->UpdateQueryBuilder($objQueryBuilder);
				} catch (QCallerException $objExc) {
					$objExc->IncrementOffset();
					throw $objExc;
				}

			// Iterate through all the Optional Clauses (if any) and perform accordingly
			if ($objOptionalClauses) {
				if ($objOptionalClauses instanceof QQClause)
					$objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
				else if (is_array($objOptionalClauses))
					foreach ($objOptionalClauses as $objClause)
						$objClause->UpdateQueryBuilder($objQueryBuilder);
				else
					throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
			}

			// Get the SQL Statement
			$strQuery = $objQueryBuilder->GetStatement();

			// Prepare the Statement with the Query Parameters (if applicable)
			if ($mixParameterArray) {
				if (is_array($mixParameterArray)) {
					if (count($mixParameterArray))
						$strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);

					// Ensure that there are no other Unresolved Named Parameters
					if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
						throw new QCallerException('Unresolved named parameters in the query');
				} else
					throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
			}

			// Return the Objects
			return $strQuery;
		}

		/**
		 * Static Qcubed Query method to query for a single BuildVersion object.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return BuildVersion the queried object
		 */
		public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = BuildVersion::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Perform the Query, Get the First Row, and Instantiate a new BuildVersion object
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);

			// Do we have to expand anything?
			if ($objQueryBuilder->ExpandAsArrayNodes) {
				$objToReturn = array();
				while ($objDbRow = $objDbResult->GetNextRow()) {
					$objItem = BuildVersion::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, $objToReturn, $objQueryBuilder->ColumnAliasArray);
					if ($objItem)
						$objToReturn[] = $objItem;
				}
				if (count($objToReturn)) {
					// Since we only want the object to return, lets return the object and not the array.
					return $objToReturn[0];
				} else {
					return null;
				}
			} else {
				// No expands just return the first row
				$objDbRow = $objDbResult->GetNextRow();
				if(null === $objDbRow)
					return null;
				return BuildVersion::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
			}
		}

		/**
		 * Static Qcubed Query method to query for an array of BuildVersion objects.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return BuildVersion[] the queried objects as an array
		 */
		public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = BuildVersion::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Perform the Query and Instantiate the Array Result
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);
			return BuildVersion::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
		}

		/**
		 * Static Qcubed Query method to query for a count of BuildVersion objects.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return integer the count of queried objects as an integer
		 */
		public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = BuildVersion::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Perform the Query and return the row_count
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);

			// Figure out if the query is using GroupBy
			$blnGrouped = false;

			if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
				if ($objClause instanceof QQGroupBy) {
					$blnGrouped = true;
					break;
				}
			}

			if ($blnGrouped)
				// Groups in this query - return the count of Groups (which is the count of all rows)
				return $objDbResult->CountRows();
			else {
				// No Groups - return the sql-calculated count(*) value
				$strDbRow = $objDbResult->FetchRow();
				return QType::Cast($strDbRow[0], QType::Integer);
			}
		}

		public static function QueryArrayCached(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null, $blnForceUpdate = false) {
			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();

			$strQuery = BuildVersion::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);

			$objCache = new QCache('qquery/buildversion', $strQuery);
			$cacheData = $objCache->GetData();

			if (!$cacheData || $blnForceUpdate) {
				$objDbResult = $objQueryBuilder->Database->Query($strQuery);
				$arrResult = BuildVersion::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
				$objCache->SaveData(serialize($arrResult));
			} else {
				$arrResult = unserialize($cacheData);
			}

			return $arrResult;
		}

		/**
		 * Updates a QQueryBuilder with the SELECT fields for this BuildVersion
		 * @param QQueryBuilder $objBuilder the Query Builder object to update
		 * @param string $strPrefix optional prefix to add to the SELECT fields
		 */
		public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
			if ($strPrefix) {
				$strTableName = $strPrefix;
				$strAliasPrefix = $strPrefix . '__';
			} else {
				$strTableName = 'build_version';
				$strAliasPrefix = '';
			}

			$objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
			$objBuilder->AddSelectItem($strTableName, 'project_id', $strAliasPrefix . 'project_id');
			$objBuilder->AddSelectItem($strTableName, 'major_version', $strAliasPrefix . 'major_version');
			$objBuilder->AddSelectItem($strTableName, 'minor_version', $strAliasPrefix . 'minor_version');
			$objBuilder->AddSelectItem($strTableName, 'hot_patch', $strAliasPrefix . 'hot_patch');
			$objBuilder->AddSelectItem($strTableName, 'release_candidate', $strAliasPrefix . 'release_candidate');
			$objBuilder->AddSelectItem($strTableName, 'date_created', $strAliasPrefix . 'date_created');
			$objBuilder->AddSelectItem($strTableName, 'date_modified', $strAliasPrefix . 'date_modified');
			$objBuilder->AddSelectItem($strTableName, 'create_user_id', $strAliasPrefix . 'create_user_id');
			$objBuilder->AddSelectItem($strTableName, 'status', $strAliasPrefix . 'status');
		}



		///////////////////////////////
		// INSTANTIATION-RELATED METHODS
		///////////////////////////////

		/**
		 * Instantiate a BuildVersion from a Database Row.
		 * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
		 * is calling this BuildVersion::InstantiateDbRow in order to perform
		 * early binding on referenced objects.
		 * @param DatabaseRowBase $objDbRow
		 * @param string $strAliasPrefix
		 * @param string $strExpandAsArrayNodes
		 * @param QBaseClass $arrPreviousItem
		 * @param string[] $strColumnAliasArray
		 * @return BuildVersion
		*/
		public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $arrPreviousItems = null, $strColumnAliasArray = array()) {
			// If blank row, return null
			if (!$objDbRow) {
				return null;
			}

			// Create a new instance of the BuildVersion object
			$objToReturn = new BuildVersion();
			$objToReturn->__blnRestored = true;

			$strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
			$objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'project_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'project_id'] : $strAliasPrefix . 'project_id';
			$objToReturn->intProjectId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'major_version', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'major_version'] : $strAliasPrefix . 'major_version';
			$objToReturn->intMajorVersion = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'minor_version', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'minor_version'] : $strAliasPrefix . 'minor_version';
			$objToReturn->intMinorVersion = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'hot_patch', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'hot_patch'] : $strAliasPrefix . 'hot_patch';
			$objToReturn->intHotPatch = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'release_candidate', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'release_candidate'] : $strAliasPrefix . 'release_candidate';
			$objToReturn->intReleaseCandidate = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'date_created', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'date_created'] : $strAliasPrefix . 'date_created';
			$objToReturn->dttDateCreated = $objDbRow->GetColumn($strAliasName, 'DateTime');
			$strAliasName = array_key_exists($strAliasPrefix . 'date_modified', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'date_modified'] : $strAliasPrefix . 'date_modified';
			$objToReturn->dttDateModified = $objDbRow->GetColumn($strAliasName, 'DateTime');
			$strAliasName = array_key_exists($strAliasPrefix . 'create_user_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'create_user_id'] : $strAliasPrefix . 'create_user_id';
			$objToReturn->intCreateUserId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'status', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'status'] : $strAliasPrefix . 'status';
			$objToReturn->intStatus = $objDbRow->GetColumn($strAliasName, 'Integer');

			if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
				foreach ($arrPreviousItems as $objPreviousItem) {
					if ($objToReturn->Id != $objPreviousItem->Id) {
						continue;
					}

					// complete match - all primary key columns are the same
					return null;
				}
			}

			// Instantiate Virtual Attributes
			foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
				$strVirtualPrefix = $strAliasPrefix . '__';
				$strVirtualPrefixLength = strlen($strVirtualPrefix);
				if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
					$objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
			}

			// Prepare to Check for Early/Virtual Binding
			if (!$strAliasPrefix)
				$strAliasPrefix = 'build_version__';




			return $objToReturn;
		}

		/**
		 * Instantiate an array of BuildVersions from a Database Result
		 * @param DatabaseResultBase $objDbResult
		 * @param string $strExpandAsArrayNodes
		 * @param string[] $strColumnAliasArray
		 * @return BuildVersion[]
		 */
		public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
			$objToReturn = array();

			if (!$strColumnAliasArray)
				$strColumnAliasArray = array();

			// If blank resultset, then return empty array
			if (!$objDbResult)
				return $objToReturn;

			// Load up the return array with each row
			if ($strExpandAsArrayNodes) {
				$objToReturn = array();
				while ($objDbRow = $objDbResult->GetNextRow()) {
					$objItem = BuildVersion::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objToReturn, $strColumnAliasArray);
					if ($objItem) {
						$objToReturn[] = $objItem;
					}
				}
			} else {
				while ($objDbRow = $objDbResult->GetNextRow())
					$objToReturn[] = BuildVersion::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
			}

			return $objToReturn;
		}



		///////////////////////////////////////////////////
		// INDEX-BASED LOAD METHODS (Single Load and Array)
		///////////////////////////////////////////////////
			
		/**
		 * Load a single BuildVersion object,
		 * by Id Index(es)
		 * @param integer $intId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion
		*/
		public static function LoadById($intId, $objOptionalClauses = null) {
			return BuildVersion::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::BuildVersion()->Id, $intId)
				),
				$objOptionalClauses
			);
		}
			
		/**
		 * Load an array of BuildVersion objects,
		 * by ProjectId Index(es)
		 * @param integer $intProjectId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion[]
		*/
		public static function LoadArrayByProjectId($intProjectId, $objOptionalClauses = null) {
			// Call BuildVersion::QueryArray to perform the LoadArrayByProjectId query
			try {
				return BuildVersion::QueryArray(
					QQ::Equal(QQN::BuildVersion()->ProjectId, $intProjectId),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count BuildVersions
		 * by ProjectId Index(es)
		 * @param integer $intProjectId
		 * @return int
		*/
		public static function CountByProjectId($intProjectId) {
			// Call BuildVersion::QueryCount to perform the CountByProjectId query
			return BuildVersion::QueryCount(
				QQ::Equal(QQN::BuildVersion()->ProjectId, $intProjectId)
			);
		}
			
		/**
		 * Load an array of BuildVersion objects,
		 * by CreateUserId Index(es)
		 * @param integer $intCreateUserId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion[]
		*/
		public static function LoadArrayByCreateUserId($intCreateUserId, $objOptionalClauses = null) {
			// Call BuildVersion::QueryArray to perform the LoadArrayByCreateUserId query
			try {
				return BuildVersion::QueryArray(
					QQ::Equal(QQN::BuildVersion()->CreateUserId, $intCreateUserId),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count BuildVersions
		 * by CreateUserId Index(es)
		 * @param integer $intCreateUserId
		 * @return int
		*/
		public static function CountByCreateUserId($intCreateUserId) {
			// Call BuildVersion::QueryCount to perform the CountByCreateUserId query
			return BuildVersion::QueryCount(
				QQ::Equal(QQN::BuildVersion()->CreateUserId, $intCreateUserId)
			);
		}
			
		/**
		 * Load an array of BuildVersion objects,
		 * by Status Index(es)
		 * @param integer $intStatus
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion[]
		*/
		public static function LoadArrayByStatus($intStatus, $objOptionalClauses = null) {
			// Call BuildVersion::QueryArray to perform the LoadArrayByStatus query
			try {
				return BuildVersion::QueryArray(
					QQ::Equal(QQN::BuildVersion()->Status, $intStatus),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count BuildVersions
		 * by Status Index(es)
		 * @param integer $intStatus
		 * @return int
		*/
		public static function CountByStatus($intStatus) {
			// Call BuildVersion::QueryCount to perform the CountByStatus query
			return BuildVersion::QueryCount(
				QQ::Equal(QQN::BuildVersion()->Status, $intStatus)
			);
		}
			
		/**
		 * Load an array of BuildVersion objects,
		 * by ProjectId, Status Index(es)
		 * @param integer $intProjectId
		 * @param integer $intStatus
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return BuildVersion[]
		*/
		public static function LoadArrayByProjectIdStatus($intProjectId, $intStatus, $objOptionalClauses = null) {
			// Call BuildVersion::QueryArray to perform the LoadArrayByProjectIdStatus query
			try {
				return BuildVersion::QueryArray(
					QQ::AndCondition(
					QQ::Equal(QQN::BuildVersion()->ProjectId, $intProjectId),
					QQ::Equal(QQN::BuildVersion()->Status, $intStatus)
					),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count BuildVersions
		 * by ProjectId, Status Index(es)
		 * @param integer $intProjectId
		 * @param integer $intStatus
		 * @return int
		*/
		public static function CountByProjectIdStatus($intProjectId, $intStatus) {
			// Call BuildVersion::QueryCount to perform the CountByProjectIdStatus query
			return BuildVersion::QueryCount(
				QQ::AndCondition(
				QQ::Equal(QQN::BuildVersion()->ProjectId, $intProjectId),
				QQ::Equal(QQN::BuildVersion()->Status, $intStatus)
				)
			);
		}



		////////////////////////////////////////////////////
		// INDEX-BASED LOAD METHODS (Array via Many to Many)
		////////////////////////////////////////////////////




		//////////////////////////
		// SAVE, DELETE AND RELOAD
		//////////////////////////

		/**
		 * Save this BuildVersion
		 * @param bool $blnForceInsert
		 * @param bool $blnForceUpdate
		 * @return int
		 */
		public function Save($blnForceInsert = false, $blnForceUpdate = false) {
			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();

			$mixToReturn = null;

			try {
				if ((!$this->__blnRestored) || ($blnForceInsert)) {
					// Perform an INSERT query
					$objDatabase->NonQuery('
						INSERT INTO `build_version` (
							`project_id`,
							`major_version`,
							`minor_version`,
							`hot_patch`,
							`release_candidate`,
							`date_created`,
							`date_modified`,
							`create_user_id`,
							`status`
						) VALUES (
							' . $objDatabase->SqlVariable($this->intProjectId) . ',
							' . $objDatabase->SqlVariable($this->intMajorVersion) . ',
							' . $objDatabase->SqlVariable($this->intMinorVersion) . ',
							' . $objDatabase->SqlVariable($this->intHotPatch) . ',
							' . $objDatabase->SqlVariable($this->intReleaseCandidate) . ',
							' . $objDatabase->SqlVariable($this->dttDateCreated) . ',
							' . $objDatabase->SqlVariable($this->dttDateModified) . ',
							' . $objDatabase->SqlVariable($this->intCreateUserId) . ',
							' . $objDatabase->SqlVariable($this->intStatus) . '
						)
					');

					// Update Identity column and return its value
					$mixToReturn = $this->intId = $objDatabase->InsertId('build_version', 'id');
				} else {
					// Perform an UPDATE query

					// First checking for Optimistic Locking constraints (if applicable)

					// Perform the UPDATE query
					$objDatabase->NonQuery('
						UPDATE
							`build_version`
						SET
							`project_id` = ' . $objDatabase->SqlVariable($this->intProjectId) . ',
							`major_version` = ' . $objDatabase->SqlVariable($this->intMajorVersion) . ',
							`minor_version` = ' . $objDatabase->SqlVariable($this->intMinorVersion) . ',
							`hot_patch` = ' . $objDatabase->SqlVariable($this->intHotPatch) . ',
							`release_candidate` = ' . $objDatabase->SqlVariable($this->intReleaseCandidate) . ',
							`date_created` = ' . $objDatabase->SqlVariable($this->dttDateCreated) . ',
							`date_modified` = ' . $objDatabase->SqlVariable($this->dttDateModified) . ',
							`create_user_id` = ' . $objDatabase->SqlVariable($this->intCreateUserId) . ',
							`status` = ' . $objDatabase->SqlVariable($this->intStatus) . '
						WHERE
							`id` = ' . $objDatabase->SqlVariable($this->intId) . '
					');
				}

			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Update __blnRestored and any Non-Identity PK Columns (if applicable)
			$this->__blnRestored = true;


			// Return
			return $mixToReturn;
		}

		/**
		 * Delete this BuildVersion
		 * @return void
		 */
		public function Delete() {
			if ((is_null($this->intId)))
				throw new QUndefinedPrimaryKeyException('Cannot delete this BuildVersion with an unset primary key.');

			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();


			// Perform the SQL Query
			$objDatabase->NonQuery('
				DELETE FROM
					`build_version`
				WHERE
					`id` = ' . $objDatabase->SqlVariable($this->intId) . '');
		}

		/**
		 * Delete all BuildVersions
		 * @return void
		 */
		public static function DeleteAll() {
			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();

			// Perform the Query
			$objDatabase->NonQuery('
				DELETE FROM
					`build_version`');
		}

		/**
		 * Truncate build_version table
		 * @return void
		 */
		public static function Truncate() {
			// Get the Database Object for this Class
			$objDatabase = BuildVersion::GetDatabase();

			// Perform the Query
			$objDatabase->NonQuery('
				TRUNCATE `build_version`');
		}

		/**
		 * Reload this BuildVersion from the database.
		 * @return void
		 */
		public function Reload() {
			// Make sure we are actually Restored from the database
			if (!$this->__blnRestored)
				throw new QCallerException('Cannot call Reload() on a new, unsaved BuildVersion object.');

			// Reload the Object
			$objReloaded = BuildVersion::Load($this->intId);

			// Update $this's local variables to match
			$this->intProjectId = $objReloaded->intProjectId;
			$this->intMajorVersion = $objReloaded->intMajorVersion;
			$this->intMinorVersion = $objReloaded->intMinorVersion;
			$this->intHotPatch = $objReloaded->intHotPatch;
			$this->intReleaseCandidate = $objReloaded->intReleaseCandidate;
			$this->dttDateCreated = $objReloaded->dttDateCreated;
			$this->dttDateModified = $objReloaded->dttDateModified;
			$this->intCreateUserId = $objReloaded->intCreateUserId;
			$this->intStatus = $objReloaded->intStatus;
		}



		////////////////////
		// PUBLIC OVERRIDERS
		////////////////////

				/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				///////////////////
				// Member Variables
				///////////////////
				case 'Id':
					/**
					 * Gets the value for intId (Read-Only PK)
					 * @return integer
					 */
					return $this->intId;

				case 'ProjectId':
					/**
					 * Gets the value for intProjectId 
					 * @return integer
					 */
					return $this->intProjectId;

				case 'MajorVersion':
					/**
					 * Gets the value for intMajorVersion 
					 * @return integer
					 */
					return $this->intMajorVersion;

				case 'MinorVersion':
					/**
					 * Gets the value for intMinorVersion 
					 * @return integer
					 */
					return $this->intMinorVersion;

				case 'HotPatch':
					/**
					 * Gets the value for intHotPatch 
					 * @return integer
					 */
					return $this->intHotPatch;

				case 'ReleaseCandidate':
					/**
					 * Gets the value for intReleaseCandidate 
					 * @return integer
					 */
					return $this->intReleaseCandidate;

				case 'DateCreated':
					/**
					 * Gets the value for dttDateCreated 
					 * @return QDateTime
					 */
					return $this->dttDateCreated;

				case 'DateModified':
					/**
					 * Gets the value for dttDateModified 
					 * @return QDateTime
					 */
					return $this->dttDateModified;

				case 'CreateUserId':
					/**
					 * Gets the value for intCreateUserId 
					 * @return integer
					 */
					return $this->intCreateUserId;

				case 'Status':
					/**
					 * Gets the value for intStatus (Not Null)
					 * @return integer
					 */
					return $this->intStatus;


				///////////////////
				// Member Objects
				///////////////////

				////////////////////////////
				// Virtual Object References (Many to Many and Reverse References)
				// (If restored via a "Many-to" expansion)
				////////////////////////////


				case '__Restored':
					return $this->__blnRestored;

				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

				/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			switch ($strName) {
				///////////////////
				// Member Variables
				///////////////////
				case 'ProjectId':
					/**
					 * Sets the value for intProjectId 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intProjectId = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'MajorVersion':
					/**
					 * Sets the value for intMajorVersion 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intMajorVersion = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'MinorVersion':
					/**
					 * Sets the value for intMinorVersion 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intMinorVersion = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'HotPatch':
					/**
					 * Sets the value for intHotPatch 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intHotPatch = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'ReleaseCandidate':
					/**
					 * Sets the value for intReleaseCandidate 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intReleaseCandidate = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'DateCreated':
					/**
					 * Sets the value for dttDateCreated 
					 * @param QDateTime $mixValue
					 * @return QDateTime
					 */
					try {
						return ($this->dttDateCreated = QType::Cast($mixValue, QType::DateTime));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'DateModified':
					/**
					 * Sets the value for dttDateModified 
					 * @param QDateTime $mixValue
					 * @return QDateTime
					 */
					try {
						return ($this->dttDateModified = QType::Cast($mixValue, QType::DateTime));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'CreateUserId':
					/**
					 * Sets the value for intCreateUserId 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intCreateUserId = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'Status':
					/**
					 * Sets the value for intStatus (Not Null)
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intStatus = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}


				///////////////////
				// Member Objects
				///////////////////
				default:
					try {
						return parent::__set($strName, $mixValue);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Lookup a VirtualAttribute value (if applicable).  Returns NULL if none found.
		 * @param string $strName
		 * @return string
		 */
		public function GetVirtualAttribute($strName) {
			if (array_key_exists($strName, $this->__strVirtualAttributeArray))
				return $this->__strVirtualAttributeArray[$strName];
			return null;
		}



		///////////////////////////////
		// ASSOCIATED OBJECTS' METHODS
		///////////////////////////////





		////////////////////////////////////////
		// METHODS for SOAP-BASED WEB SERVICES
		////////////////////////////////////////

		public static function GetSoapComplexTypeXml() {
			$strToReturn = '<complexType name="BuildVersion"><sequence>';
			$strToReturn .= '<element name="Id" type="xsd:int"/>';
			$strToReturn .= '<element name="ProjectId" type="xsd:int"/>';
			$strToReturn .= '<element name="MajorVersion" type="xsd:int"/>';
			$strToReturn .= '<element name="MinorVersion" type="xsd:int"/>';
			$strToReturn .= '<element name="HotPatch" type="xsd:int"/>';
			$strToReturn .= '<element name="ReleaseCandidate" type="xsd:int"/>';
			$strToReturn .= '<element name="DateCreated" type="xsd:dateTime"/>';
			$strToReturn .= '<element name="DateModified" type="xsd:dateTime"/>';
			$strToReturn .= '<element name="CreateUserId" type="xsd:int"/>';
			$strToReturn .= '<element name="Status" type="xsd:int"/>';
			$strToReturn .= '<element name="__blnRestored" type="xsd:boolean"/>';
			$strToReturn .= '</sequence></complexType>';
			return $strToReturn;
		}

		public static function AlterSoapComplexTypeArray(&$strComplexTypeArray) {
			if (!array_key_exists('BuildVersion', $strComplexTypeArray)) {
				$strComplexTypeArray['BuildVersion'] = BuildVersion::GetSoapComplexTypeXml();
			}
		}

		public static function GetArrayFromSoapArray($objSoapArray) {
			$objArrayToReturn = array();

			foreach ($objSoapArray as $objSoapObject)
				array_push($objArrayToReturn, BuildVersion::GetObjectFromSoapObject($objSoapObject));

			return $objArrayToReturn;
		}

		public static function GetObjectFromSoapObject($objSoapObject) {
			$objToReturn = new BuildVersion();
			if (property_exists($objSoapObject, 'Id'))
				$objToReturn->intId = $objSoapObject->Id;
			if (property_exists($objSoapObject, 'ProjectId'))
				$objToReturn->intProjectId = $objSoapObject->ProjectId;
			if (property_exists($objSoapObject, 'MajorVersion'))
				$objToReturn->intMajorVersion = $objSoapObject->MajorVersion;
			if (property_exists($objSoapObject, 'MinorVersion'))
				$objToReturn->intMinorVersion = $objSoapObject->MinorVersion;
			if (property_exists($objSoapObject, 'HotPatch'))
				$objToReturn->intHotPatch = $objSoapObject->HotPatch;
			if (property_exists($objSoapObject, 'ReleaseCandidate'))
				$objToReturn->intReleaseCandidate = $objSoapObject->ReleaseCandidate;
			if (property_exists($objSoapObject, 'DateCreated'))
				$objToReturn->dttDateCreated = new QDateTime($objSoapObject->DateCreated);
			if (property_exists($objSoapObject, 'DateModified'))
				$objToReturn->dttDateModified = new QDateTime($objSoapObject->DateModified);
			if (property_exists($objSoapObject, 'CreateUserId'))
				$objToReturn->intCreateUserId = $objSoapObject->CreateUserId;
			if (property_exists($objSoapObject, 'Status'))
				$objToReturn->intStatus = $objSoapObject->Status;
			if (property_exists($objSoapObject, '__blnRestored'))
				$objToReturn->__blnRestored = $objSoapObject->__blnRestored;
			return $objToReturn;
		}

		public static function GetSoapArrayFromArray($objArray) {
			if (!$objArray)
				return null;

			$objArrayToReturn = array();

			foreach ($objArray as $objObject)
				array_push($objArrayToReturn, BuildVersion::GetSoapObjectFromObject($objObject, true));

			return unserialize(serialize($objArrayToReturn));
		}

		public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) {
			if ($objObject->dttDateCreated)
				$objObject->dttDateCreated = $objObject->dttDateCreated->qFormat(QDateTime::FormatSoap);
			if ($objObject->dttDateModified)
				$objObject->dttDateModified = $objObject->dttDateModified->qFormat(QDateTime::FormatSoap);
			return $objObject;
		}


		////////////////////////////////////////
		// METHODS for JSON Object Translation
		////////////////////////////////////////

		// this function is required for objects that implement the
		// IteratorAggregate interface
		public function getIterator() {
			///////////////////
			// Member Variables
			///////////////////
			$iArray['Id'] = $this->intId;
			$iArray['ProjectId'] = $this->intProjectId;
			$iArray['MajorVersion'] = $this->intMajorVersion;
			$iArray['MinorVersion'] = $this->intMinorVersion;
			$iArray['HotPatch'] = $this->intHotPatch;
			$iArray['ReleaseCandidate'] = $this->intReleaseCandidate;
			$iArray['DateCreated'] = $this->dttDateCreated;
			$iArray['DateModified'] = $this->dttDateModified;
			$iArray['CreateUserId'] = $this->intCreateUserId;
			$iArray['Status'] = $this->intStatus;
			return new ArrayIterator($iArray);
		}

		// this function returns a Json formatted string using the
		// IteratorAggregate interface
		public function getJson() {
			return json_encode($this->getIterator());
		}


	}



	/////////////////////////////////////
	// ADDITIONAL CLASSES for QCubed QUERY
	/////////////////////////////////////

    /**
     * @uses QQNode
     *
     * @property-read QQNode $Id
     * @property-read QQNode $ProjectId
     * @property-read QQNode $MajorVersion
     * @property-read QQNode $MinorVersion
     * @property-read QQNode $HotPatch
     * @property-read QQNode $ReleaseCandidate
     * @property-read QQNode $DateCreated
     * @property-read QQNode $DateModified
     * @property-read QQNode $CreateUserId
     * @property-read QQNode $Status
     *
     *

     * @property-read QQNode $_PrimaryKeyNode
     **/
	class QQNodeBuildVersion extends QQNode {
		protected $strTableName = 'build_version';
		protected $strPrimaryKey = 'id';
		protected $strClassName = 'BuildVersion';
		public function __get($strName) {
			switch ($strName) {
				case 'Id':
					return new QQNode('id', 'Id', 'Integer', $this);
				case 'ProjectId':
					return new QQNode('project_id', 'ProjectId', 'Integer', $this);
				case 'MajorVersion':
					return new QQNode('major_version', 'MajorVersion', 'Integer', $this);
				case 'MinorVersion':
					return new QQNode('minor_version', 'MinorVersion', 'Integer', $this);
				case 'HotPatch':
					return new QQNode('hot_patch', 'HotPatch', 'Integer', $this);
				case 'ReleaseCandidate':
					return new QQNode('release_candidate', 'ReleaseCandidate', 'Integer', $this);
				case 'DateCreated':
					return new QQNode('date_created', 'DateCreated', 'DateTime', $this);
				case 'DateModified':
					return new QQNode('date_modified', 'DateModified', 'DateTime', $this);
				case 'CreateUserId':
					return new QQNode('create_user_id', 'CreateUserId', 'Integer', $this);
				case 'Status':
					return new QQNode('status', 'Status', 'Integer', $this);

				case '_PrimaryKeyNode':
					return new QQNode('id', 'Id', 'Integer', $this);
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
	}

    /**
     * @property-read QQNode $Id
     * @property-read QQNode $ProjectId
     * @property-read QQNode $MajorVersion
     * @property-read QQNode $MinorVersion
     * @property-read QQNode $HotPatch
     * @property-read QQNode $ReleaseCandidate
     * @property-read QQNode $DateCreated
     * @property-read QQNode $DateModified
     * @property-read QQNode $CreateUserId
     * @property-read QQNode $Status
     *
     *

     * @property-read QQNode $_PrimaryKeyNode
     **/
	class QQReverseReferenceNodeBuildVersion extends QQReverseReferenceNode {
		protected $strTableName = 'build_version';
		protected $strPrimaryKey = 'id';
		protected $strClassName = 'BuildVersion';
		public function __get($strName) {
			switch ($strName) {
				case 'Id':
					return new QQNode('id', 'Id', 'integer', $this);
				case 'ProjectId':
					return new QQNode('project_id', 'ProjectId', 'integer', $this);
				case 'MajorVersion':
					return new QQNode('major_version', 'MajorVersion', 'integer', $this);
				case 'MinorVersion':
					return new QQNode('minor_version', 'MinorVersion', 'integer', $this);
				case 'HotPatch':
					return new QQNode('hot_patch', 'HotPatch', 'integer', $this);
				case 'ReleaseCandidate':
					return new QQNode('release_candidate', 'ReleaseCandidate', 'integer', $this);
				case 'DateCreated':
					return new QQNode('date_created', 'DateCreated', 'QDateTime', $this);
				case 'DateModified':
					return new QQNode('date_modified', 'DateModified', 'QDateTime', $this);
				case 'CreateUserId':
					return new QQNode('create_user_id', 'CreateUserId', 'integer', $this);
				case 'Status':
					return new QQNode('status', 'Status', 'integer', $this);

				case '_PrimaryKeyNode':
					return new QQNode('id', 'Id', 'integer', $this);
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
	}

?>
